package org.dromara.api.rank;

import org.dromara.api.rank.modules.UserRankDTO;
import org.dromara.common.core.domain.R;
import org.springframework.cloud.openfeign.FallbackFactory;

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
//Component作用是创建bean
@Component

//FallbackFactory作用是创建一个降级类
public class RemoteRankServiceFallbackFactory implements FallbackFactory<RemoteRankService> {

   //private static final Logger log = LoggerFactory.getLogger(RemoteRankServiceFallbackFactory.class);
    //Override作用是重写父类方法
    @Override
    public RemoteRankService create(Throwable cause){
        log.error("积分调用失败:{}", cause.getMessage());
        return new RemoteRankService() {
            @Override
            public R<UserRankDTO> getUserRank(Long userId) {
                return R.fail("积分服务调用失败");
            }

            @Override
            public R<List<UserRankDTO>> getTopRank(Integer count) {
                return R.fail("积分服务调用失败");
            }
        };
    }
}
